export function toRef(...refs) {
    return computed(() => {
        return {
            validate: () => {
                const formRefs = []
                for (const ref of refs) {
                    const refValue = unref(ref)
                    if (refValue) {
                        if (refValue instanceof Array) {
                            formRefs.push(...refValue)
                        } else {
                            formRefs.push(refValue)
                        }
                    }
                }
                return Promise.all(formRefs.map(formRef => formRef.validate()))
            }
        }
    })
}

export function pass(fn, ...refs) {
    const formRefs = []
    for (const ref of refs) {
        const refValue = unref(ref)
        if (refValue) {
            if (refValue instanceof Array) {
                formRefs.push(...refValue)
            } else {
                formRefs.push(refValue)
            }
        }
    }
    Promise.all(formRefs.map(formRef => formRef.validate()))
    .then(() => {
        console.log('校验通过')
        fn && fn()
    }).catch(() => {
        console.log('校验未通过')
    })
}
